package com.hrpmar.controller;

import com.hrpmar.controller.dto.PurplanDto;
import com.hrpmar.service.AuditService;
import com.hrpmar.utils.Pager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by c on 2017-11-20.
 */
@RestController
@RequestMapping("/audit")
public class AuditRestController {
    @Resource
    private AuditService auditService;

    @GetMapping("searchPendingAudit")
    public Pager searchPendingAudit(PurplanDto dto,Integer offset,Integer limit){
        Pager pager = auditService.searchPendingAudit(dto,offset, limit);
        return pager;
    }

    @RequestMapping("/search")
    public Pager search(Integer offset, Integer limit, PurplanDto condition){
        Pager pager = auditService.search(offset,limit,condition);
        return pager;
    }

    @PostMapping("/auditpur")
    public String auditPurplan(String planNum, Integer planChstate, String planViews){
        String flag = "false";
        try{
            auditService.auditPurplan(planNum,planChstate,planViews);
            flag="true";
        }catch (RuntimeException e){
            flag="false";
        }
        return flag;
    }
    @PostMapping("auditdes")
    public String auditdes(String desNum,Integer desAuditstate,String desViews){
        String flag = "false";
        try{
            auditService.auditDestorymaster(desNum,desAuditstate,desViews);
            flag="true";
        }catch (RuntimeException e){
            flag="false";
        }
        return flag;
    }
}
